import request from '@/utils/request.js'

// 获取所有权限
export const getPowerListAPI = function(type) {
  return request.get(`/rights/${type}`)
}
// 获取角色列表
export const getUserPowerListAPI = function() {
  return request.get('/roles')
}
// 添加角色
export const postRolesAPI = function(data) {
  return request.post('/roles', data)
}
// 删除角色
export const delRolesAPI = function(id) {
  return request.delete(`/roles/${id}`)
}
// 修改角色
export const changeRolesAPI = function(id, data) {
  return request.put(`/roles/${id}`, data)
}
// 删除角色指定权限
export const deleteRightByIdAPI = function(roleId, rightId) {
  return request.delete(`roles/${roleId}/rights/${rightId}`)
}
// 角色权限修改api
export const postRolesRightAPI = function(roleId, rids) {
  return request.post(`roles/${roleId}/rights`, { rids: rids })
}
// 分配用户角色
export const putUserRolesAPI = function(id, rid) {
  return request.put(`users/${id}/role`, { rid: rid })
}
export default {
  getPowerListAPI,
  getUserPowerListAPI,
  postRolesAPI,
  delRolesAPI,
  changeRolesAPI,
  deleteRightByIdAPI,
  postRolesRightAPI,
  putUserRolesAPI
}
